package com.hxqh.services;

import net.jctp.CThostFtdcInvestorPositionDetailField;
import net.jctp.CThostFtdcInvestorPositionField;
import net.jctp.CThostFtdcRspUserLoginField;
import net.jctp.CThostFtdcTradeField;
import net.jctp.CThostFtdcTradingAccountField;
import net.jtrader.JTraderException;

import com.hxqh.jctptrader.helper.TraderHelper;

public class TraderService {

	private TraderHelper tradeHelper;
	private CThostFtdcRspUserLoginField Cuser;

	public void submitMarketPriceOrder(long orderRef, String futuresCode,
			int sell, int direction, int tradeNum) {
		tradeHelper.submitMarketPriceOrder(Cuser.BrokerID, Cuser.UserID,
				futuresCode, String.valueOf(orderRef),
				sell == 0 ? true : false, direction == 0 ? true : false,
				tradeNum);
	}

	public void submitLimitPriceOrder(long orderRef, String futuresCode,
			int sell, int direction, int tradeNum, double tradePrice) {
		tradeHelper.submitLimitPriceOrder(Cuser.BrokerID, Cuser.UserID,
				futuresCode, String.valueOf(orderRef),
				sell == 0 ? true : false, direction == 0 ? true : false,
				tradeNum, tradePrice);
	}

	public CThostFtdcTradeField getRspQryTrade() throws JTraderException {
		return tradeHelper.reqQryTrade(Cuser.UserID, Cuser.BrokerID);
	}

	public CThostFtdcTradingAccountField getTradingAccount()
			throws JTraderException {
		return tradeHelper.ReqQryTradingAccount(Cuser.BrokerID, Cuser.UserID);
	}

	public CThostFtdcInvestorPositionDetailField[] getHoldInfoDetailField(
			Integer userId, Integer brokerId) throws JTraderException {
		return tradeHelper.ReqQryInvestorPositionDetail(brokerId.toString(), userId.toString());
	}
	
	public CThostFtdcInvestorPositionDetailField[] getHoldInfoDetailField(
			Integer userId, Integer brokerId, String futuresCode) throws JTraderException {
		return tradeHelper.ReqQryInvestorPositionDetail(brokerId.toString(), userId.toString());
	}
	
	public CThostFtdcInvestorPositionField[] getHoldInfoField(Integer userId, Integer brokerId) throws JTraderException {
		return tradeHelper.ReqQryInvestorPosition(brokerId.toString(), userId.toString());
	}

	public TraderHelper getTradeHelper() {
		return tradeHelper;
	}

	public void setTradeHelper(TraderHelper tradeHelper) {
		this.tradeHelper = tradeHelper;
	}

	public CThostFtdcRspUserLoginField getCuser() {
		return Cuser;
	}

	public void setCuser(CThostFtdcRspUserLoginField cuser) {
		Cuser = cuser;
	}

}
